import { createSSRApp } from "vue";
import * as Pinia from "pinia";
import tmui from "./tmui";
import App from "./App.vue";
import { config } from "./config";

//#ifndef H5
const updateManager = uni.getUpdateManager();

updateManager.onUpdateReady(function (res) {
  uni.showModal({
    title: "更新提示",
    content: "新版本已经准备好，是否重启应用？",
    success(res) {
      if (res.confirm) {
        // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
        updateManager.applyUpdate();
      }
    },
  });
});

//#endif

export function createApp() {
  const app = createSSRApp(App);
  app.use(tmui, config);
  return {
    app,
    Pinia,
  };
}
